#include <iostream>
#include <sys/types.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
using namespace std;
void CleanupChild(int signo)
{
    // v3
    while (true)
    {
        if (signo == SIGCHLD)
        {
            pid_t rid = waitpid(-1, nullptr, WNOHANG); // -1说明等待任何一个子进程.
            if (rid > 0)
            {
                cout << "wait success" << "rid:" << rid << endl;
            }else{
                break;
            }
        }
    }
    cout << "wait child done!" << endl;
}

int main()
{
    signal(SIGCHLD, SIG_IGN);
    pid_t id = fork();
    if (id == 0)
    {
        int cnt = 5;
        while (cnt--)
        {
            cout << "pid:" << getpid() << endl;
            sleep(1);
        }
        cout << "child exit" << endl;
        exit(0);
    }
    while (true)
        sleep(1);
    return 0;
}